// Copyright (C) 1953-2023 NUDT
// Verilog module name - time_sync_computing 
// Version: V4.3.0.20231129
// Created:
//         by - fenglin 
////////////////////////////////////////////////////////////////////////////
// Description:
//         global time synchronization 
///////////////////////////////////////////////////////////////////////////

`timescale 1ns / 1ps

module time_sync_computing 
#(
parameter local_module_id = 12'd0,
parameter PTP_RX_OFFSET_XGMII = 16'd131,
parameter PTP_TX_OFFSET_XGMII = 16'd58,     
parameter PTP_RX_OFFSET_GMII = 16'd192,
parameter PTP_TX_OFFSET_GMII = 16'd72, 
parameter clk_period = {8'd8,41'h0}//8ns
)
(
        i_clk,
        i_rst_n,
       
        i_wr         ,      
        iv_wdata     ,      
        iv_addr      ,      
        i_rd         ,           
        o_wr         ,       
        ov_rdata     ,        
        ov_raddr     ,  

        i_tsnnic_or_tsnswitch ,//1:tsnnic.  0:tsnswitch        
       
        ov_localclk     ,
		o_local_cnt_rst ,
		iv_hcp_mid      ,
		ov_master_port  ,
		o_sync_ok       ,
		o_sync_ok_wr    ,
        ov_port_ptp_enabled,
        o_sync_step_mode,
        i_cyclestart    ,
		  ov_frequency_cor,
		
		iv_data      ,
		i_data_wr    ,
		
		ov_data      ,
		o_data_wr    ,
        
        ov_data_report            ,      
        o_data_wr_report          ,
 		
		i_osm_req_tx_pulse_p0     ,     
		i_osm_resp_rx_pulse_p0    ,     
		i_osm_req_tx_pulse_p1     ,     
		i_osm_resp_rx_pulse_p1    ,     
		i_osm_req_tx_pulse_p2     ,     
		i_osm_resp_rx_pulse_p2    ,     
		i_osm_req_tx_pulse_p3     ,     
		i_osm_resp_rx_pulse_p3    ,     
		i_osm_req_tx_pulse_p4     ,     
		i_osm_resp_rx_pulse_p4    ,     
		i_osm_req_tx_pulse_p5     ,     
		i_osm_resp_rx_pulse_p5    ,     
		i_osm_req_tx_pulse_p6     ,     
		i_osm_resp_rx_pulse_p6    ,     
		i_osm_req_tx_pulse_p7     ,     
		i_osm_resp_rx_pulse_p7    ,     
		i_osm_req_tx_pulse_p8     ,     
		i_osm_resp_rx_pulse_p8    ,     
		i_osm_req_tx_pulse_p9     ,     
		i_osm_resp_rx_pulse_p9    ,     
		i_osm_req_tx_pulse_p10    ,     
		i_osm_resp_rx_pulse_p10   ,     
		i_osm_req_tx_pulse_p11    ,     
		i_osm_resp_rx_pulse_p11   ,     
		i_osm_req_tx_pulse_p12    ,     
		i_osm_resp_rx_pulse_p12   ,     
		i_osm_req_tx_pulse_p13    ,     
		i_osm_resp_rx_pulse_p13   ,     
		i_osm_req_tx_pulse_p14    ,     
		i_osm_resp_rx_pulse_p14   ,     
		i_osm_req_tx_pulse_p15    ,     
		i_osm_resp_rx_pulse_p15   ,     
		i_osm_req_tx_pulse_p16    ,     
		i_osm_resp_rx_pulse_p16   ,     
		i_osm_req_tx_pulse_p17    ,     
		i_osm_resp_rx_pulse_p17   ,     
		i_osm_req_tx_pulse_p18    ,     
		i_osm_resp_rx_pulse_p18   ,     
		i_osm_req_tx_pulse_p19    ,     
		i_osm_resp_rx_pulse_p19   ,     
		i_osm_req_tx_pulse_p20    ,     
		i_osm_resp_rx_pulse_p20   ,     
		i_osm_req_tx_pulse_p21    ,     
		i_osm_resp_rx_pulse_p21   ,     
		i_osm_req_tx_pulse_p22    ,     
		i_osm_resp_rx_pulse_p22   ,     
		i_osm_req_tx_pulse_p23    ,     
		i_osm_resp_rx_pulse_p23   ,     
		i_osm_req_tx_pulse_p24    ,     
		i_osm_resp_rx_pulse_p24   ,     
		i_osm_req_tx_pulse_p25    ,     
		i_osm_resp_rx_pulse_p25   ,     
		i_osm_req_tx_pulse_p26    ,     
		i_osm_resp_rx_pulse_p26   ,     
		i_osm_req_tx_pulse_p27    ,     
		i_osm_resp_rx_pulse_p27   ,     
		i_osm_req_tx_pulse_p28    ,     
		i_osm_resp_rx_pulse_p28   ,     
		i_osm_req_tx_pulse_p29    ,     
		i_osm_resp_rx_pulse_p29   ,     
		i_osm_req_tx_pulse_p30    ,     
		i_osm_resp_rx_pulse_p30   ,     
		i_osm_req_tx_pulse_p31    ,     
		i_osm_resp_rx_pulse_p31   , 

        i_osm_req_rx_pulse_p0     ,
		i_osm_resp_tx_pulse_p0    ,
		i_osm_req_rx_pulse_p1     ,
		i_osm_resp_tx_pulse_p1    ,
		i_osm_req_rx_pulse_p2     ,
		i_osm_resp_tx_pulse_p2    ,
		i_osm_req_rx_pulse_p3     ,
		i_osm_resp_tx_pulse_p3    ,
		i_osm_req_rx_pulse_p4     ,
		i_osm_resp_tx_pulse_p4    ,
		i_osm_req_rx_pulse_p5     ,
		i_osm_resp_tx_pulse_p5    ,
		i_osm_req_rx_pulse_p6     ,
		i_osm_resp_tx_pulse_p6    ,
		i_osm_req_rx_pulse_p7     ,
		i_osm_resp_tx_pulse_p7    ,
		i_osm_req_rx_pulse_p8     ,
		i_osm_resp_tx_pulse_p8    ,
		i_osm_req_rx_pulse_p9     ,
		i_osm_resp_tx_pulse_p9    ,
		i_osm_req_rx_pulse_p10    ,
		i_osm_resp_tx_pulse_p10   ,
		i_osm_req_rx_pulse_p11    ,
		i_osm_resp_tx_pulse_p11   ,
		i_osm_req_rx_pulse_p12    ,
		i_osm_resp_tx_pulse_p12   ,
		i_osm_req_rx_pulse_p13    ,
		i_osm_resp_tx_pulse_p13   ,
		i_osm_req_rx_pulse_p14    ,
		i_osm_resp_tx_pulse_p14   ,
		i_osm_req_rx_pulse_p15    ,
		i_osm_resp_tx_pulse_p15   ,
		i_osm_req_rx_pulse_p16    ,
		i_osm_resp_tx_pulse_p16   ,
		i_osm_req_rx_pulse_p17    ,
		i_osm_resp_tx_pulse_p17   ,
		i_osm_req_rx_pulse_p18    ,
		i_osm_resp_tx_pulse_p18   ,
		i_osm_req_rx_pulse_p19    ,
		i_osm_resp_tx_pulse_p19   ,
		i_osm_req_rx_pulse_p20    ,
		i_osm_resp_tx_pulse_p20   ,
		i_osm_req_rx_pulse_p21    ,
		i_osm_resp_tx_pulse_p21   ,
		i_osm_req_rx_pulse_p22    ,
		i_osm_resp_tx_pulse_p22   ,
		i_osm_req_rx_pulse_p23    ,
		i_osm_resp_tx_pulse_p23   ,
		i_osm_req_rx_pulse_p24    ,
		i_osm_resp_tx_pulse_p24   ,
		i_osm_req_rx_pulse_p25    ,
		i_osm_resp_tx_pulse_p25   ,
		i_osm_req_rx_pulse_p26    ,
		i_osm_resp_tx_pulse_p26   ,
		i_osm_req_rx_pulse_p27    ,
		i_osm_resp_tx_pulse_p27   ,
		i_osm_req_rx_pulse_p28    ,
		i_osm_resp_tx_pulse_p28   ,
		i_osm_req_rx_pulse_p29    ,
		i_osm_resp_tx_pulse_p29   ,
		i_osm_req_rx_pulse_p30    ,
		i_osm_resp_tx_pulse_p30   ,
		i_osm_req_rx_pulse_p31    ,
		i_osm_resp_tx_pulse_p31   ,
        
        o_sync_generate_pulse     
);
// clk & rst
input                  i_clk;
input                  i_rst_n;

input                  i_wr;
input      [31:0]      iv_wdata;
input      [18:0]      iv_addr;      
input                  i_rd;
output                 o_wr; 
output     [31:0]      ov_rdata;  
output     [18:0]      ov_raddr;

input                  i_tsnnic_or_tsnswitch ;

output     [79:0]      ov_localclk       ;
output                 o_local_cnt_rst   ;
input      [11:0]      iv_hcp_mid        ;
output     [31:0]      ov_master_port    ;
output                 o_sync_ok         ;
output                 o_sync_ok_wr      ;
output     [31:0]      ov_port_ptp_enabled	                    ;
output                 o_sync_step_mode  ;
input                  i_cyclestart      ;
output     [48:0]      ov_frequency_cor  ;

(*MARK_DEBUG="true"*)input	   [8:0]	   iv_data          ;
(*MARK_DEBUG="true"*)input	         	   i_data_wr        ;

(*MARK_DEBUG="true"*)output	   [8:0]	   ov_data          ;
(*MARK_DEBUG="true"*)output	         	   o_data_wr        ;

(*MARK_DEBUG="true"*)output     [8:0]       ov_data_report   ;
(*MARK_DEBUG="true"*)output                 o_data_wr_report ;

input                  i_osm_req_tx_pulse_p0   ;
input                  i_osm_resp_rx_pulse_p0  ;
input                  i_osm_req_tx_pulse_p1   ;
input                  i_osm_resp_rx_pulse_p1  ;
input                  i_osm_req_tx_pulse_p2   ;
input                  i_osm_resp_rx_pulse_p2  ;
input                  i_osm_req_tx_pulse_p3   ;
input                  i_osm_resp_rx_pulse_p3  ;
input                  i_osm_req_tx_pulse_p4   ;
input                  i_osm_resp_rx_pulse_p4  ;
input                  i_osm_req_tx_pulse_p5   ;
input                  i_osm_resp_rx_pulse_p5  ;
input                  i_osm_req_tx_pulse_p6   ;
input                  i_osm_resp_rx_pulse_p6  ;
input                  i_osm_req_tx_pulse_p7   ;
input                  i_osm_resp_rx_pulse_p7  ;
input                  i_osm_req_tx_pulse_p8   ;
input                  i_osm_resp_rx_pulse_p8  ;
input                  i_osm_req_tx_pulse_p9   ;
input                  i_osm_resp_rx_pulse_p9  ;
input                  i_osm_req_tx_pulse_p10  ;
input                  i_osm_resp_rx_pulse_p10 ;
input                  i_osm_req_tx_pulse_p11  ;
input                  i_osm_resp_rx_pulse_p11 ;
input                  i_osm_req_tx_pulse_p12  ;
input                  i_osm_resp_rx_pulse_p12 ;
input                  i_osm_req_tx_pulse_p13  ;
input                  i_osm_resp_rx_pulse_p13 ;
input                  i_osm_req_tx_pulse_p14  ;
input                  i_osm_resp_rx_pulse_p14 ;
input                  i_osm_req_tx_pulse_p15  ;
input                  i_osm_resp_rx_pulse_p15 ;
input                  i_osm_req_tx_pulse_p16  ;
input                  i_osm_resp_rx_pulse_p16 ;
input                  i_osm_req_tx_pulse_p17  ;
input                  i_osm_resp_rx_pulse_p17 ;
input                  i_osm_req_tx_pulse_p18  ;
input                  i_osm_resp_rx_pulse_p18 ;
input                  i_osm_req_tx_pulse_p19  ;
input                  i_osm_resp_rx_pulse_p19 ;
input                  i_osm_req_tx_pulse_p20  ;
input                  i_osm_resp_rx_pulse_p20 ;
input                  i_osm_req_tx_pulse_p21  ;
input                  i_osm_resp_rx_pulse_p21 ;
input                  i_osm_req_tx_pulse_p22  ;
input                  i_osm_resp_rx_pulse_p22 ;
input                  i_osm_req_tx_pulse_p23  ;
input                  i_osm_resp_rx_pulse_p23 ;
input                  i_osm_req_tx_pulse_p24  ;
input                  i_osm_resp_rx_pulse_p24 ;
input                  i_osm_req_tx_pulse_p25  ;
input                  i_osm_resp_rx_pulse_p25 ;
input                  i_osm_req_tx_pulse_p26  ;
input                  i_osm_resp_rx_pulse_p26 ;
input                  i_osm_req_tx_pulse_p27  ;
input                  i_osm_resp_rx_pulse_p27 ;
input                  i_osm_req_tx_pulse_p28  ;
input                  i_osm_resp_rx_pulse_p28 ;
input                  i_osm_req_tx_pulse_p29  ;
input                  i_osm_resp_rx_pulse_p29 ;
input                  i_osm_req_tx_pulse_p30  ;
input                  i_osm_resp_rx_pulse_p30 ;
input                  i_osm_req_tx_pulse_p31  ;
input                  i_osm_resp_rx_pulse_p31 ;

input                  i_osm_req_rx_pulse_p0   ;
input                  i_osm_resp_tx_pulse_p0  ;
input                  i_osm_req_rx_pulse_p1   ;
input                  i_osm_resp_tx_pulse_p1  ;
input                  i_osm_req_rx_pulse_p2   ;
input                  i_osm_resp_tx_pulse_p2  ;
input                  i_osm_req_rx_pulse_p3   ;
input                  i_osm_resp_tx_pulse_p3  ;
input                  i_osm_req_rx_pulse_p4   ;
input                  i_osm_resp_tx_pulse_p4  ;
input                  i_osm_req_rx_pulse_p5   ;
input                  i_osm_resp_tx_pulse_p5  ;
input                  i_osm_req_rx_pulse_p6   ;
input                  i_osm_resp_tx_pulse_p6  ;
input                  i_osm_req_rx_pulse_p7   ;
input                  i_osm_resp_tx_pulse_p7  ;
input                  i_osm_req_rx_pulse_p8   ;
input                  i_osm_resp_tx_pulse_p8  ;
input                  i_osm_req_rx_pulse_p9   ;
input                  i_osm_resp_tx_pulse_p9  ;
input                  i_osm_req_rx_pulse_p10  ;
input                  i_osm_resp_tx_pulse_p10 ;
input                  i_osm_req_rx_pulse_p11  ;
input                  i_osm_resp_tx_pulse_p11 ;
input                  i_osm_req_rx_pulse_p12  ;
input                  i_osm_resp_tx_pulse_p12 ;
input                  i_osm_req_rx_pulse_p13  ;
input                  i_osm_resp_tx_pulse_p13 ;
input                  i_osm_req_rx_pulse_p14  ;
input                  i_osm_resp_tx_pulse_p14 ;
input                  i_osm_req_rx_pulse_p15  ;
input                  i_osm_resp_tx_pulse_p15 ;
input                  i_osm_req_rx_pulse_p16  ;
input                  i_osm_resp_tx_pulse_p16 ;
input                  i_osm_req_rx_pulse_p17  ;
input                  i_osm_resp_tx_pulse_p17 ;
input                  i_osm_req_rx_pulse_p18  ;
input                  i_osm_resp_tx_pulse_p18 ;
input                  i_osm_req_rx_pulse_p19  ;
input                  i_osm_resp_tx_pulse_p19 ;
input                  i_osm_req_rx_pulse_p20  ;
input                  i_osm_resp_tx_pulse_p20 ;
input                  i_osm_req_rx_pulse_p21  ;
input                  i_osm_resp_tx_pulse_p21 ;
input                  i_osm_req_rx_pulse_p22  ;
input                  i_osm_resp_tx_pulse_p22 ;
input                  i_osm_req_rx_pulse_p23  ;
input                  i_osm_resp_tx_pulse_p23 ;
input                  i_osm_req_rx_pulse_p24  ;
input                  i_osm_resp_tx_pulse_p24 ;
input                  i_osm_req_rx_pulse_p25  ;
input                  i_osm_resp_tx_pulse_p25 ;
input                  i_osm_req_rx_pulse_p26  ;
input                  i_osm_resp_tx_pulse_p26 ;
input                  i_osm_req_rx_pulse_p27  ;
input                  i_osm_resp_tx_pulse_p27 ;
input                  i_osm_req_rx_pulse_p28  ;
input                  i_osm_resp_tx_pulse_p28 ;
input                  i_osm_req_rx_pulse_p29  ;
input                  i_osm_resp_tx_pulse_p29 ;
input                  i_osm_req_rx_pulse_p30  ;
input                  i_osm_resp_tx_pulse_p30 ;
input                  i_osm_req_rx_pulse_p31  ;
input                  i_osm_resp_tx_pulse_p31 ;

output                 o_sync_generate_pulse;
					   
wire       [11:0]      wv_os_cid_mpe2other                              ;
wire                   w_gm_role_mpe2gnp                                ; 
//wire                   w_sync_step_mode_mpe2other                       ;
wire       [3:0]       wv_sync_period_mpe2gnp                           ;
wire       [11:0]      wv_offset_threshold_mpe2snp                      ;
//wire       [16:0]      iv_sync_state                                    ;
wire       [48:0]      wv_frequency_cor_mpe2snp                         ;
wire                   w_frequency_cor_wr_mpe2snp                       ;
wire                   wv_measure_sync_state_report_enabled_mpe2cre     ;

wire       [3:0]       wv_measure_period_mpe2mrq                        ;
wire       [2:0]       wv_measure_responder_wait_time_mpe2mrq           ;

wire       [31:0]      wv_cumulativescaledrateoffset_mpe2snp            ;
wire       [15:0]      wv_measure_req_tx_cnt_p0_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p0_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p1_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p1_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p2_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p2_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p3_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p3_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p4_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p4_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p5_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p5_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p6_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p6_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p7_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p7_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p8_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p8_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p9_mrq2mpe                 ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p9_mrq2mpe        ;
wire       [15:0]      wv_measure_req_tx_cnt_p10_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p10_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p11_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p11_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p12_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p12_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p13_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p13_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p14_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p14_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p15_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p15_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p16_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p16_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p17_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p17_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p18_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p18_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p19_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p19_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p20_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p20_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p21_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p21_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p22_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p22_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p23_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p23_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p24_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p24_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p25_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p25_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p26_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p26_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p27_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p27_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p28_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p28_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p29_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p29_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p30_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p30_mrq2mpe       ;
wire       [15:0]      wv_measure_req_tx_cnt_p31_mrq2mpe                ;
wire       [15:0]      wv_measure_resp_rx_timeout_cnt_p31_mrq2mpe       ;

wire       [15:0]      wv_req_sequence_mrq2gnp                          ;

wire       [8:0]	   wv_data_osp2mrq    ;
wire      	           w_data_wr_osp2mrq  ;
wire       [8:0]	   wv_data_osp2mrs    ;
wire      	           w_data_wr_osp2mrs  ;
wire       [8:0]	   wv_data_osp2snp        ;
wire      	           w_data_wr_osp2snp      ;
wire       [7:0]       wv_tsmp_subtype_osp2snp;

wire       [8:0]	   wv_data_osp2sip    ; 
wire      	           w_data_wr_osp2sip  ;
 
wire       [8:0]	   wv_data_osp2anp    ;
wire      	           w_data_wr_osp2anp  ;

wire       [95:0]      wv_mea_clk_mct2other   ;

wire       [39:0]      wv_local_count_snp2gnp ;

wire       [8:0]	   wv_data_mrq2oss        ;
wire      	           w_data_wr_mrq2oss      ;

wire       [95:0]      wv_t1_mrq2cre                  ;
wire       [95:0]      wv_t2_mrq2cre                  ;
wire       [95:0]      wv_t3_mrq2cre                  ;
wire       [95:0]      wv_t4_mrq2cre                  ;
wire       [4:0]       wv_timestamps_port_id_mrq2cre  ;
wire                   w_timestamps_valid_mrq2cre     ;

wire       [27:0]      wv_link_delay_mrq2snp          ;
wire       [4:0]       wv_link_delay_id_mrq2snp       ;
wire                   w_link_delay_valid_mrq2snp     ;

wire       [8:0]	   wv_data_mrs2oss                ;
wire      	           w_data_wr_mrs2oss              ;

wire       [8:0]	   wv_data_gnp2oss                ;
wire      	           w_data_wr_gnp2oss              ;

wire       [8:0]	   wv_data_sip2oss                ;
wire      	           w_data_wr_sip2oss              ;

wire       [8:0]	   wv_data_anp2oss                ;
wire      	           w_data_wr_anp2oss              ;

wire       [31:0]      wv_cumulativescaledrateoffset_snp2cre  ;
wire                   w_cumulativescaledrateoffset_wr_snp2cre;

wire       [48:0]      wv_frequency_cor_snp2cre       ;

wire       [79:0]	   wv_gm_timestamps_snp2cre         ;
wire       [63:0]	   wv_correctfield_time_snp2cre     ;
wire       [39:0]	   wv_local_cnt_rx_snp2cre          ;
wire       [63:0]      wv_sync_correctfield_time_snp2cre;
wire       [27:0]      wv_sync_link_delay_snp2cre       ;
wire        	       w_time_info_valid_snp2cre        ; 

wire       [95:0]	   wv_clk_set_snp2cre               ;
wire      	           w_clk_set_wr_snp2cre             ;
wire       [39:0]      wv_current_local_count_snp2cre   ;
wire       [95:0]      wv_current_sync_clk_snp2cre      ;

wire       [12:0]      wv_offset_snp2cre     ; 
wire                   w_offset_wr_snp2cre   ;
wire       [15:0]      wv_offset_abnormal_cnt_snp2other;
wire                   w_sync_result_wr_snp2cre        ;

wire       [8:0]	   wv_data_snp2oss                 ;
wire      	           w_data_wr_snp2oss               ;

wire       [8:0]       wv_data_gss2oss                 ;
wire                   w_data_wr_gss2oss               ;
wire                   w_snp_sync_ok                   ;
assign  o_sync_ok = w_snp_sync_ok| w_gm_role_mpe2gnp   ;//gm节点的syn_ok信号��?直为1
assign ov_frequency_cor = wv_frequency_cor_snp2cre;
mbus_parse_and_encapsulate_osc mbus_parse_and_encapsulate_osc_inst
(
.i_clk                          (i_clk  ),
.i_rst_n                        (i_rst_n),
						        
.i_wr                           (i_wr    ),
.iv_wdata                       (iv_wdata),
.iv_addr                        (iv_addr ),      
.i_rd                           (i_rd    ),                      
.o_wr                           (o_wr    ), 
.ov_rdata                       (ov_rdata),
.ov_raddr                       (ov_raddr),
						        
.iv_sync_clk                    (ov_localclk                ),
.ov_os_cid                      (wv_os_cid_mpe2other        ),   
.o_gm_role                      (w_gm_role_mpe2gnp          ),
.o_sync_step_mode               (o_sync_step_mode),//(w_sync_step_mode_mpe2other ), 
.ov_sync_period                 (wv_sync_period_mpe2gnp     ), 
.ov_offset_threshold            (wv_offset_threshold_mpe2snp),
.iv_sync_state                  ({o_sync_ok,wv_offset_abnormal_cnt_snp2other}),
.ov_frequency_cor               (wv_frequency_cor_mpe2snp  ),
.o_frequency_cor_wr             (w_frequency_cor_wr_mpe2snp),
.o_state_report_enabled         (wv_measure_sync_state_report_enabled_mpe2cre),
.ov_port_ptp_enabled            (ov_port_ptp_enabled           ),
.ov_measure_period              (wv_measure_period_mpe2mrq             ),
.ov_measure_responder_wait_time (wv_measure_responder_wait_time_mpe2mrq),
.ov_master_port                 (ov_master_port),
.ov_cumulativescaledrateoffset  (wv_cumulativescaledrateoffset_mpe2snp ),
.iv_measure_req_cnt_p0             (wv_measure_req_tx_cnt_p0_mrq2mpe                 ), 
.iv_measure_resp_cnt_p0            (wv_measure_resp_rx_timeout_cnt_p0_mrq2mpe        ),
.iv_measure_req_cnt_p1             (wv_measure_req_tx_cnt_p1_mrq2mpe                 ),
.iv_measure_resp_cnt_p1            (wv_measure_resp_rx_timeout_cnt_p1_mrq2mpe        ),
.iv_measure_req_cnt_p2             (wv_measure_req_tx_cnt_p2_mrq2mpe                 ),
.iv_measure_resp_cnt_p2            (wv_measure_resp_rx_timeout_cnt_p2_mrq2mpe        ),
.iv_measure_req_cnt_p3             (wv_measure_req_tx_cnt_p3_mrq2mpe                 ),
.iv_measure_resp_cnt_p3            (wv_measure_resp_rx_timeout_cnt_p3_mrq2mpe        ),
.iv_measure_req_cnt_p4             (wv_measure_req_tx_cnt_p4_mrq2mpe                 ),
.iv_measure_resp_cnt_p4            (wv_measure_resp_rx_timeout_cnt_p4_mrq2mpe        ),
.iv_measure_req_cnt_p5             (wv_measure_req_tx_cnt_p5_mrq2mpe                 ),
.iv_measure_resp_cnt_p5            (wv_measure_resp_rx_timeout_cnt_p5_mrq2mpe        ),
.iv_measure_req_cnt_p6             (wv_measure_req_tx_cnt_p6_mrq2mpe                 ),
.iv_measure_resp_cnt_p6            (wv_measure_resp_rx_timeout_cnt_p6_mrq2mpe        ),
.iv_measure_req_cnt_p7             (wv_measure_req_tx_cnt_p7_mrq2mpe                 ),
.iv_measure_resp_cnt_p7            (wv_measure_resp_rx_timeout_cnt_p7_mrq2mpe        ),
.iv_measure_req_cnt_p8             (wv_measure_req_tx_cnt_p8_mrq2mpe                 ),
.iv_measure_resp_cnt_p8            (wv_measure_resp_rx_timeout_cnt_p8_mrq2mpe        ),
.iv_measure_req_cnt_p9             (wv_measure_req_tx_cnt_p9_mrq2mpe                 ),
.iv_measure_resp_cnt_p9            (wv_measure_resp_rx_timeout_cnt_p9_mrq2mpe        ),
.iv_measure_req_cnt_p10            (wv_measure_req_tx_cnt_p10_mrq2mpe                ),
.iv_measure_resp_cnt_p10           (wv_measure_resp_rx_timeout_cnt_p10_mrq2mpe       ),
.iv_measure_req_cnt_p11            (wv_measure_req_tx_cnt_p11_mrq2mpe                ),
.iv_measure_resp_cnt_p11           (wv_measure_resp_rx_timeout_cnt_p11_mrq2mpe       ),
.iv_measure_req_cnt_p12            (wv_measure_req_tx_cnt_p12_mrq2mpe                ),
.iv_measure_resp_cnt_p12           (wv_measure_resp_rx_timeout_cnt_p12_mrq2mpe       ),
.iv_measure_req_cnt_p13            (wv_measure_req_tx_cnt_p13_mrq2mpe                ),
.iv_measure_resp_cnt_p13           (wv_measure_resp_rx_timeout_cnt_p13_mrq2mpe       ),
.iv_measure_req_cnt_p14            (wv_measure_req_tx_cnt_p14_mrq2mpe                ),
.iv_measure_resp_cnt_p14           (wv_measure_resp_rx_timeout_cnt_p14_mrq2mpe       ),
.iv_measure_req_cnt_p15            (wv_measure_req_tx_cnt_p15_mrq2mpe                ),
.iv_measure_resp_cnt_p15           (wv_measure_resp_rx_timeout_cnt_p15_mrq2mpe       ),
.iv_measure_req_cnt_p16            (wv_measure_req_tx_cnt_p16_mrq2mpe                ),
.iv_measure_resp_cnt_p16           (wv_measure_resp_rx_timeout_cnt_p16_mrq2mpe       ),
.iv_measure_req_cnt_p17            (wv_measure_req_tx_cnt_p17_mrq2mpe                ),
.iv_measure_resp_cnt_p17           (wv_measure_resp_rx_timeout_cnt_p17_mrq2mpe       ),
.iv_measure_req_cnt_p18            (wv_measure_req_tx_cnt_p18_mrq2mpe                ),
.iv_measure_resp_cnt_p18           (wv_measure_resp_rx_timeout_cnt_p18_mrq2mpe       ),
.iv_measure_req_cnt_p19            (wv_measure_req_tx_cnt_p19_mrq2mpe                ),
.iv_measure_resp_cnt_p19           (wv_measure_resp_rx_timeout_cnt_p19_mrq2mpe       ),
.iv_measure_req_cnt_p20            (wv_measure_req_tx_cnt_p20_mrq2mpe                ),
.iv_measure_resp_cnt_p20           (wv_measure_resp_rx_timeout_cnt_p20_mrq2mpe       ),
.iv_measure_req_cnt_p21            (wv_measure_req_tx_cnt_p21_mrq2mpe                ),
.iv_measure_resp_cnt_p21           (wv_measure_resp_rx_timeout_cnt_p21_mrq2mpe       ),
.iv_measure_req_cnt_p22            (wv_measure_req_tx_cnt_p22_mrq2mpe                ),
.iv_measure_resp_cnt_p22           (wv_measure_resp_rx_timeout_cnt_p22_mrq2mpe       ),
.iv_measure_req_cnt_p23            (wv_measure_req_tx_cnt_p23_mrq2mpe                ),
.iv_measure_resp_cnt_p23           (wv_measure_resp_rx_timeout_cnt_p23_mrq2mpe       ),
.iv_measure_req_cnt_p24            (wv_measure_req_tx_cnt_p24_mrq2mpe                ),
.iv_measure_resp_cnt_p24           (wv_measure_resp_rx_timeout_cnt_p24_mrq2mpe       ),
.iv_measure_req_cnt_p25            (wv_measure_req_tx_cnt_p25_mrq2mpe                ),
.iv_measure_resp_cnt_p25           (wv_measure_resp_rx_timeout_cnt_p25_mrq2mpe       ),
.iv_measure_req_cnt_p26            (wv_measure_req_tx_cnt_p26_mrq2mpe                ),
.iv_measure_resp_cnt_p26           (wv_measure_resp_rx_timeout_cnt_p26_mrq2mpe       ),
.iv_measure_req_cnt_p27            (wv_measure_req_tx_cnt_p27_mrq2mpe                ),
.iv_measure_resp_cnt_p27           (wv_measure_resp_rx_timeout_cnt_p27_mrq2mpe       ),
.iv_measure_req_cnt_p28            (wv_measure_req_tx_cnt_p28_mrq2mpe                ),
.iv_measure_resp_cnt_p28           (wv_measure_resp_rx_timeout_cnt_p28_mrq2mpe       ),
.iv_measure_req_cnt_p29            (wv_measure_req_tx_cnt_p29_mrq2mpe                ),
.iv_measure_resp_cnt_p29           (wv_measure_resp_rx_timeout_cnt_p29_mrq2mpe       ),
.iv_measure_req_cnt_p30            (wv_measure_req_tx_cnt_p30_mrq2mpe                ),
.iv_measure_resp_cnt_p30           (wv_measure_resp_rx_timeout_cnt_p30_mrq2mpe       ),
.iv_measure_req_cnt_p31            (wv_measure_req_tx_cnt_p31_mrq2mpe                ),
.iv_measure_resp_cnt_p31           (wv_measure_resp_rx_timeout_cnt_p31_mrq2mpe       )
);

opensync_protocol_parse opensync_protocol_parse_inst
(
    .i_clk           (i_clk        ),
    .i_rst_n         (i_rst_n      ),
	                  
    .iv_data         (iv_data      ),
	.i_data_wr       (i_data_wr    ),
                      
	.ov_data_mrq     (wv_data_osp2mrq   ),
	.o_data_wr_mrq   (w_data_wr_osp2mrq ),
	                                  
	.ov_data_mrs     (wv_data_osp2mrs  ), 
	.o_data_wr_mrs   (w_data_wr_osp2mrs), 
	                                      
    .ov_data_snp     (wv_data_osp2snp  ),
	.o_data_wr_snp   (w_data_wr_osp2snp),
    .ov_tsmp_subtype (wv_tsmp_subtype_osp2snp),
                
    .ov_data_sip     (wv_data_osp2sip  ),
	.o_data_wr_sip   (w_data_wr_osp2sip),
                   
    .ov_data_anp     (wv_data_osp2anp  ),
	.o_data_wr_anp   (w_data_wr_osp2anp)      
);
signaling_process 
#(
.local_module_id(local_module_id),
.clk_period(clk_period)
)
signaling_process_inst
(
    .i_clk                                 (i_clk  ),
    .i_rst_n                               (i_rst_n),
 
    .iv_data                               (wv_data_osp2sip  ),
	.i_data_wr                             (w_data_wr_osp2sip),
    
    .iv_port_ptp_enabled                   (ov_port_ptp_enabled),
	.iv_signaling_period                   (wv_measure_period_mpe2mrq),
 
	.iv_hcp_mid                            (iv_hcp_mid         ),
                                           
	.ov_data                               (wv_data_sip2oss  ),
	.o_data_wr                             (w_data_wr_sip2oss)                                 
);
announce_process 
#(
.local_module_id(local_module_id),
.clk_period     (clk_period     )
)
announce_process_inst
(
    .i_clk                 (i_clk             ),
    .i_rst_n               (i_rst_n           ),
                            
    .i_gm_role             (w_gm_role_mpe2gnp         ),
	.iv_announce_period    (wv_sync_period_mpe2gnp    ),
    .i_tsnnic_or_tsnswitch (i_tsnnic_or_tsnswitch     ),//1:tsnnic.  0:tsnswitch
                            
	.iv_hcp_mid            (iv_hcp_mid        ),
                            
    .iv_data               (wv_data_osp2anp           ),
    .i_data_wr             (w_data_wr_osp2anp         ),
                            
	.ov_data               (wv_data_anp2oss           ),
	.o_data_wr             (w_data_wr_anp2oss         )                                 
);
measure_request 
#(
.local_module_id(local_module_id),
.PTP_RX_OFFSET_XGMII(PTP_RX_OFFSET_XGMII),
.PTP_TX_OFFSET_XGMII(PTP_TX_OFFSET_XGMII),
.PTP_RX_OFFSET_GMII(PTP_RX_OFFSET_GMII),
.PTP_TX_OFFSET_GMII(PTP_TX_OFFSET_GMII),
.clk_period     (clk_period     )
)
measure_request_inst
(
    .i_clk                                 (i_clk  ),
    .i_rst_n                               (i_rst_n),
 
    .iv_data                               (wv_data_osp2mrq  ),
	.i_data_wr                             (w_data_wr_osp2mrq),
 
	.iv_measure_period                     (wv_measure_period_mpe2mrq             ),
	.iv_measure_responder_wait_time        (wv_measure_responder_wait_time_mpe2mrq),
	.iv_port_ptp_enabled                   (ov_port_ptp_enabled           ),
	.iv_hcp_mid                            (iv_hcp_mid                            ),
	.iv_mea_clk                            (wv_mea_clk_mct2other                  ),
 
	.ov_data                               (wv_data_mrq2oss  ),
	.o_data_wr                             (w_data_wr_mrq2oss),
	 
	.ov_t1                                 (wv_t1_mrq2cre                ),
	.ov_t2                                 (wv_t2_mrq2cre                ),
	.ov_t3                                 (wv_t3_mrq2cre                ),
	.ov_t4                                 (wv_t4_mrq2cre                ),
	.ov_timestamps_port_id                 (wv_timestamps_port_id_mrq2cre),
	.o_timestamps_valid                    (w_timestamps_valid_mrq2cre   ),
 
	.ov_link_delay                         (wv_link_delay_mrq2snp     ),
	.ov_link_delay_id                      (wv_link_delay_id_mrq2snp  ),
	.o_link_delay_valid                    (w_link_delay_valid_mrq2snp),		
 
	.i_osm_req_tx_pulse_p0                 (i_osm_req_tx_pulse_p0          ),
	.i_osm_resp_rx_pulse_p0                (i_osm_resp_rx_pulse_p0         ),
	.i_osm_req_tx_pulse_p1                 (i_osm_req_tx_pulse_p1          ),
	.i_osm_resp_rx_pulse_p1                (i_osm_resp_rx_pulse_p1         ),
	.i_osm_req_tx_pulse_p2                 (i_osm_req_tx_pulse_p2          ),
	.i_osm_resp_rx_pulse_p2                (i_osm_resp_rx_pulse_p2         ),
	.i_osm_req_tx_pulse_p3                 (i_osm_req_tx_pulse_p3          ),
	.i_osm_resp_rx_pulse_p3                (i_osm_resp_rx_pulse_p3         ),
	.i_osm_req_tx_pulse_p4                 (i_osm_req_tx_pulse_p4          ),
	.i_osm_resp_rx_pulse_p4                (i_osm_resp_rx_pulse_p4         ),
	.i_osm_req_tx_pulse_p5                 (i_osm_req_tx_pulse_p5          ),
	.i_osm_resp_rx_pulse_p5                (i_osm_resp_rx_pulse_p5         ),
	.i_osm_req_tx_pulse_p6                 (i_osm_req_tx_pulse_p6          ),
	.i_osm_resp_rx_pulse_p6                (i_osm_resp_rx_pulse_p6         ),
	.i_osm_req_tx_pulse_p7                 (i_osm_req_tx_pulse_p7          ),
	.i_osm_resp_rx_pulse_p7                (i_osm_resp_rx_pulse_p7         ),
	.i_osm_req_tx_pulse_p8                 (i_osm_req_tx_pulse_p8          ),
	.i_osm_resp_rx_pulse_p8                (i_osm_resp_rx_pulse_p8         ),
	.i_osm_req_tx_pulse_p9                 (i_osm_req_tx_pulse_p9          ),
	.i_osm_resp_rx_pulse_p9                (i_osm_resp_rx_pulse_p9         ),
	.i_osm_req_tx_pulse_p10                (i_osm_req_tx_pulse_p10         ),
	.i_osm_resp_rx_pulse_p10               (i_osm_resp_rx_pulse_p10        ),
	.i_osm_req_tx_pulse_p11                (i_osm_req_tx_pulse_p11         ),
	.i_osm_resp_rx_pulse_p11               (i_osm_resp_rx_pulse_p11        ),
	.i_osm_req_tx_pulse_p12                (i_osm_req_tx_pulse_p12         ),
	.i_osm_resp_rx_pulse_p12               (i_osm_resp_rx_pulse_p12        ),
	.i_osm_req_tx_pulse_p13                (i_osm_req_tx_pulse_p13         ),
	.i_osm_resp_rx_pulse_p13               (i_osm_resp_rx_pulse_p13        ),
	.i_osm_req_tx_pulse_p14                (i_osm_req_tx_pulse_p14         ),
	.i_osm_resp_rx_pulse_p14               (i_osm_resp_rx_pulse_p14        ),
	.i_osm_req_tx_pulse_p15                (i_osm_req_tx_pulse_p15         ),
	.i_osm_resp_rx_pulse_p15               (i_osm_resp_rx_pulse_p15        ),
	.i_osm_req_tx_pulse_p16                (i_osm_req_tx_pulse_p16         ),
	.i_osm_resp_rx_pulse_p16               (i_osm_resp_rx_pulse_p16        ),
	.i_osm_req_tx_pulse_p17                (i_osm_req_tx_pulse_p17         ),
	.i_osm_resp_rx_pulse_p17               (i_osm_resp_rx_pulse_p17        ),
	.i_osm_req_tx_pulse_p18                (i_osm_req_tx_pulse_p18         ),
	.i_osm_resp_rx_pulse_p18               (i_osm_resp_rx_pulse_p18        ),
	.i_osm_req_tx_pulse_p19                (i_osm_req_tx_pulse_p19         ),
	.i_osm_resp_rx_pulse_p19               (i_osm_resp_rx_pulse_p19        ),
	.i_osm_req_tx_pulse_p20                (i_osm_req_tx_pulse_p20         ),
	.i_osm_resp_rx_pulse_p20               (i_osm_resp_rx_pulse_p20        ),
	.i_osm_req_tx_pulse_p21                (i_osm_req_tx_pulse_p21         ),
	.i_osm_resp_rx_pulse_p21               (i_osm_resp_rx_pulse_p21        ),
	.i_osm_req_tx_pulse_p22                (i_osm_req_tx_pulse_p22         ),
	.i_osm_resp_rx_pulse_p22               (i_osm_resp_rx_pulse_p22        ),
	.i_osm_req_tx_pulse_p23                (i_osm_req_tx_pulse_p23         ),
	.i_osm_resp_rx_pulse_p23               (i_osm_resp_rx_pulse_p23        ),
	.i_osm_req_tx_pulse_p24                (i_osm_req_tx_pulse_p24         ),
	.i_osm_resp_rx_pulse_p24               (i_osm_resp_rx_pulse_p24        ),	
	.i_osm_req_tx_pulse_p25                (i_osm_req_tx_pulse_p25         ),
	.i_osm_resp_rx_pulse_p25               (i_osm_resp_rx_pulse_p25        ),
	.i_osm_req_tx_pulse_p26                (i_osm_req_tx_pulse_p26         ),
	.i_osm_resp_rx_pulse_p26               (i_osm_resp_rx_pulse_p26        ),
	.i_osm_req_tx_pulse_p27                (i_osm_req_tx_pulse_p27         ),
	.i_osm_resp_rx_pulse_p27               (i_osm_resp_rx_pulse_p27        ),
	.i_osm_req_tx_pulse_p28                (i_osm_req_tx_pulse_p28         ),
	.i_osm_resp_rx_pulse_p28               (i_osm_resp_rx_pulse_p28        ),
	.i_osm_req_tx_pulse_p29                (i_osm_req_tx_pulse_p29         ),
	.i_osm_resp_rx_pulse_p29               (i_osm_resp_rx_pulse_p29        ),
	.i_osm_req_tx_pulse_p30                (i_osm_req_tx_pulse_p30         ),
	.i_osm_resp_rx_pulse_p30               (i_osm_resp_rx_pulse_p30        ),
	.i_osm_req_tx_pulse_p31                (i_osm_req_tx_pulse_p31         ),
	.i_osm_resp_rx_pulse_p31               (i_osm_resp_rx_pulse_p31        ),		
    
	.ov_measure_req_tx_cnt_p0              (wv_measure_req_tx_cnt_p0_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p0     (wv_measure_resp_rx_timeout_cnt_p0_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p1              (wv_measure_req_tx_cnt_p1_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p1     (wv_measure_resp_rx_timeout_cnt_p1_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p2              (wv_measure_req_tx_cnt_p2_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p2     (wv_measure_resp_rx_timeout_cnt_p2_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p3              (wv_measure_req_tx_cnt_p3_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p3     (wv_measure_resp_rx_timeout_cnt_p3_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p4              (wv_measure_req_tx_cnt_p4_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p4     (wv_measure_resp_rx_timeout_cnt_p4_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p5              (wv_measure_req_tx_cnt_p5_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p5     (wv_measure_resp_rx_timeout_cnt_p5_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p6              (wv_measure_req_tx_cnt_p6_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p6     (wv_measure_resp_rx_timeout_cnt_p6_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p7              (wv_measure_req_tx_cnt_p7_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p7     (wv_measure_resp_rx_timeout_cnt_p7_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p8              (wv_measure_req_tx_cnt_p8_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p8     (wv_measure_resp_rx_timeout_cnt_p8_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p9              (wv_measure_req_tx_cnt_p9_mrq2mpe           ),
	.ov_measure_resp_rx_timeout_cnt_p9     (wv_measure_resp_rx_timeout_cnt_p9_mrq2mpe  ),	
	.ov_measure_req_tx_cnt_p10             (wv_measure_req_tx_cnt_p10_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p10    (wv_measure_resp_rx_timeout_cnt_p10_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p11             (wv_measure_req_tx_cnt_p11_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p11    (wv_measure_resp_rx_timeout_cnt_p11_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p12             (wv_measure_req_tx_cnt_p12_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p12    (wv_measure_resp_rx_timeout_cnt_p12_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p13             (wv_measure_req_tx_cnt_p13_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p13    (wv_measure_resp_rx_timeout_cnt_p13_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p14             (wv_measure_req_tx_cnt_p14_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p14    (wv_measure_resp_rx_timeout_cnt_p14_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p15             (wv_measure_req_tx_cnt_p15_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p15    (wv_measure_resp_rx_timeout_cnt_p15_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p16             (wv_measure_req_tx_cnt_p16_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p16    (wv_measure_resp_rx_timeout_cnt_p16_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p17             (wv_measure_req_tx_cnt_p17_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p17    (wv_measure_resp_rx_timeout_cnt_p17_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p18             (wv_measure_req_tx_cnt_p18_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p18    (wv_measure_resp_rx_timeout_cnt_p18_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p19             (wv_measure_req_tx_cnt_p19_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p19    (wv_measure_resp_rx_timeout_cnt_p19_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p20             (wv_measure_req_tx_cnt_p20_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p20    (wv_measure_resp_rx_timeout_cnt_p20_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p21             (wv_measure_req_tx_cnt_p21_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p21    (wv_measure_resp_rx_timeout_cnt_p21_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p22             (wv_measure_req_tx_cnt_p22_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p22    (wv_measure_resp_rx_timeout_cnt_p22_mrq2mpe ),	
	.ov_measure_req_tx_cnt_p23             (wv_measure_req_tx_cnt_p23_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p23    (wv_measure_resp_rx_timeout_cnt_p23_mrq2mpe ),
    .ov_measure_req_tx_cnt_p24             (wv_measure_req_tx_cnt_p24_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p24    (wv_measure_resp_rx_timeout_cnt_p24_mrq2mpe ),
    .ov_measure_req_tx_cnt_p25             (wv_measure_req_tx_cnt_p25_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p25    (wv_measure_resp_rx_timeout_cnt_p25_mrq2mpe ),
	.ov_measure_req_tx_cnt_p26             (wv_measure_req_tx_cnt_p26_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p26    (wv_measure_resp_rx_timeout_cnt_p26_mrq2mpe ),
	.ov_measure_req_tx_cnt_p27             (wv_measure_req_tx_cnt_p27_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p27    (wv_measure_resp_rx_timeout_cnt_p27_mrq2mpe ),
	.ov_measure_req_tx_cnt_p28             (wv_measure_req_tx_cnt_p28_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p28    (wv_measure_resp_rx_timeout_cnt_p28_mrq2mpe ),
	.ov_measure_req_tx_cnt_p29             (wv_measure_req_tx_cnt_p29_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p29    (wv_measure_resp_rx_timeout_cnt_p29_mrq2mpe ),
	.ov_measure_req_tx_cnt_p30             (wv_measure_req_tx_cnt_p30_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p30    (wv_measure_resp_rx_timeout_cnt_p30_mrq2mpe ),
	.ov_measure_req_tx_cnt_p31             (wv_measure_req_tx_cnt_p31_mrq2mpe          ),
	.ov_measure_resp_rx_timeout_cnt_p31    (wv_measure_resp_rx_timeout_cnt_p31_mrq2mpe ),
    
    .ov_req_sequence                       (wv_req_sequence_mrq2gnp                    )
);

measure_response 
#(
.local_module_id(local_module_id),
.PTP_RX_OFFSET_XGMII(PTP_RX_OFFSET_XGMII),
.PTP_TX_OFFSET_XGMII(PTP_TX_OFFSET_XGMII),
.PTP_RX_OFFSET_GMII(PTP_RX_OFFSET_GMII),
.PTP_TX_OFFSET_GMII(PTP_TX_OFFSET_GMII),
.clk_period     (clk_period     )
)
measure_response_inst
(
	.i_clk                   (i_clk  ),
	.i_rst_n                 (i_rst_n),
 
	.iv_hcp_mid              (iv_hcp_mid),
 
	.iv_data                 (wv_data_osp2mrs  ),
	.i_data_wr	             (w_data_wr_osp2mrs),
 
	.iv_mea_clk              (wv_mea_clk_mct2other),
	 
	.ov_data                 (wv_data_mrs2oss  ),
	.o_data_wr               (w_data_wr_mrs2oss),
 
	.i_osm_req_rx_pulse_p0   (i_osm_req_rx_pulse_p0  ),
	.i_osm_resp_tx_pulse_p0  (i_osm_resp_tx_pulse_p0 ),
	.i_osm_req_rx_pulse_p1   (i_osm_req_rx_pulse_p1  ),
	.i_osm_resp_tx_pulse_p1  (i_osm_resp_tx_pulse_p1 ),
	.i_osm_req_rx_pulse_p2   (i_osm_req_rx_pulse_p2  ),
	.i_osm_resp_tx_pulse_p2  (i_osm_resp_tx_pulse_p2 ),
	.i_osm_req_rx_pulse_p3   (i_osm_req_rx_pulse_p3  ),
	.i_osm_resp_tx_pulse_p3  (i_osm_resp_tx_pulse_p3 ),
	.i_osm_req_rx_pulse_p4   (i_osm_req_rx_pulse_p4  ),
	.i_osm_resp_tx_pulse_p4  (i_osm_resp_tx_pulse_p4 ),
	.i_osm_req_rx_pulse_p5   (i_osm_req_rx_pulse_p5  ),
	.i_osm_resp_tx_pulse_p5  (i_osm_resp_tx_pulse_p5 ),
	.i_osm_req_rx_pulse_p6   (i_osm_req_rx_pulse_p6  ),
	.i_osm_resp_tx_pulse_p6  (i_osm_resp_tx_pulse_p6 ),
	.i_osm_req_rx_pulse_p7   (i_osm_req_rx_pulse_p7  ),
	.i_osm_resp_tx_pulse_p7  (i_osm_resp_tx_pulse_p7 ),
	.i_osm_req_rx_pulse_p8   (i_osm_req_rx_pulse_p8  ),
	.i_osm_resp_tx_pulse_p8  (i_osm_resp_tx_pulse_p8 ),
	.i_osm_req_rx_pulse_p9   (i_osm_req_rx_pulse_p9  ),
	.i_osm_resp_tx_pulse_p9  (i_osm_resp_tx_pulse_p9 ),
	.i_osm_req_rx_pulse_p10  (i_osm_req_rx_pulse_p10 ),
	.i_osm_resp_tx_pulse_p10 (i_osm_resp_tx_pulse_p10),
	.i_osm_req_rx_pulse_p11  (i_osm_req_rx_pulse_p11 ),
	.i_osm_resp_tx_pulse_p11 (i_osm_resp_tx_pulse_p11),
	.i_osm_req_rx_pulse_p12  (i_osm_req_rx_pulse_p12 ),
	.i_osm_resp_tx_pulse_p12 (i_osm_resp_tx_pulse_p12),
	.i_osm_req_rx_pulse_p13  (i_osm_req_rx_pulse_p13 ),
	.i_osm_resp_tx_pulse_p13 (i_osm_resp_tx_pulse_p13),
	.i_osm_req_rx_pulse_p14  (i_osm_req_rx_pulse_p14 ),
	.i_osm_resp_tx_pulse_p14 (i_osm_resp_tx_pulse_p14),
	.i_osm_req_rx_pulse_p15  (i_osm_req_rx_pulse_p15 ),
	.i_osm_resp_tx_pulse_p15 (i_osm_resp_tx_pulse_p15),
	.i_osm_req_rx_pulse_p16  (i_osm_req_rx_pulse_p16 ),
	.i_osm_resp_tx_pulse_p16 (i_osm_resp_tx_pulse_p16),
	.i_osm_req_rx_pulse_p17  (i_osm_req_rx_pulse_p17 ),
	.i_osm_resp_tx_pulse_p17 (i_osm_resp_tx_pulse_p17),
	.i_osm_req_rx_pulse_p18  (i_osm_req_rx_pulse_p18 ),
	.i_osm_resp_tx_pulse_p18 (i_osm_resp_tx_pulse_p18),
	.i_osm_req_rx_pulse_p19  (i_osm_req_rx_pulse_p19 ),
	.i_osm_resp_tx_pulse_p19 (i_osm_resp_tx_pulse_p19),
	.i_osm_req_rx_pulse_p20  (i_osm_req_rx_pulse_p20 ),
	.i_osm_resp_tx_pulse_p20 (i_osm_resp_tx_pulse_p20),
	.i_osm_req_rx_pulse_p21  (i_osm_req_rx_pulse_p21 ),
	.i_osm_resp_tx_pulse_p21 (i_osm_resp_tx_pulse_p21),
	.i_osm_req_rx_pulse_p22  (i_osm_req_rx_pulse_p22 ),
	.i_osm_resp_tx_pulse_p22 (i_osm_resp_tx_pulse_p22),
	.i_osm_req_rx_pulse_p23  (i_osm_req_rx_pulse_p23 ),
	.i_osm_resp_tx_pulse_p23 (i_osm_resp_tx_pulse_p23),
	.i_osm_req_rx_pulse_p24  (i_osm_req_rx_pulse_p24 ),
	.i_osm_resp_tx_pulse_p24 (i_osm_resp_tx_pulse_p24),
	.i_osm_req_rx_pulse_p25  (i_osm_req_rx_pulse_p25 ),
	.i_osm_resp_tx_pulse_p25 (i_osm_resp_tx_pulse_p25),
	.i_osm_req_rx_pulse_p26  (i_osm_req_rx_pulse_p26 ),
	.i_osm_resp_tx_pulse_p26 (i_osm_resp_tx_pulse_p26),
	.i_osm_req_rx_pulse_p27  (i_osm_req_rx_pulse_p27 ),
	.i_osm_resp_tx_pulse_p27 (i_osm_resp_tx_pulse_p27),
	.i_osm_req_rx_pulse_p28  (i_osm_req_rx_pulse_p28 ),
	.i_osm_resp_tx_pulse_p28 (i_osm_resp_tx_pulse_p28),
	.i_osm_req_rx_pulse_p29  (i_osm_req_rx_pulse_p29 ),
	.i_osm_resp_tx_pulse_p29 (i_osm_resp_tx_pulse_p29),
	.i_osm_req_rx_pulse_p30  (i_osm_req_rx_pulse_p30 ),
	.i_osm_resp_tx_pulse_p30 (i_osm_resp_tx_pulse_p30),
	.i_osm_req_rx_pulse_p31  (i_osm_req_rx_pulse_p31 ),
	.i_osm_resp_tx_pulse_p31 (i_osm_resp_tx_pulse_p31)
	
); 

grandmaster_node_process 
#(
.local_module_id(local_module_id),
.clk_period     (clk_period     )
)
grandmaster_node_process_inst
( 
    .i_clk                (i_clk                      ),
    .i_rst_n              (i_rst_n                    ),
    
    .i_sync_step_mode     (o_sync_step_mode),//(w_sync_step_mode_mpe2other ),
    .iv_req_sequence      (wv_req_sequence_mrq2gnp    ),
    
	.iv_sync_clk          (ov_localclk                ),
	.iv_local_count       (wv_local_count_snp2gnp     ),
			               		                      
	.i_gm_role            (w_gm_role_mpe2gnp          ),
	.iv_sync_period       (wv_sync_period_mpe2gnp     ),
	.iv_hcp_mid           (iv_hcp_mid                 ),
		                   	                          
	.ov_data              (wv_data_gnp2oss            )                 ,
	.o_data_wr            (w_data_wr_gnp2oss          ),

    .o_sync_generate_pulse(o_sync_generate_pulse)    
);

slave_node_process 
#(
.clk_period     (clk_period     )
)
slave_node_process_inst
(
    .i_clk                                 (i_clk  ),
    .i_rst_n                               (i_rst_n),
    
    .i_tsnnic_or_tsnswitch                 (i_tsnnic_or_tsnswitch      ),//1:tsnnic.  0:tsnswitch
    .i_sync_step_mode                      (o_sync_step_mode),//(w_sync_step_mode_mpe2other ),
 
    .iv_link_delay                         (wv_link_delay_mrq2snp     ),
	.iv_link_delay_port_id                 (wv_link_delay_id_mrq2snp  ),
	.i_link_delay_wr                       (w_link_delay_valid_mrq2snp),
 
	.iv_csrateoffset_localnode             (wv_cumulativescaledrateoffset_mpe2snp),
	.iv_offset_threshold                   (wv_offset_threshold_mpe2snp          ),
 
    .iv_data                               (wv_data_osp2snp  ),
	.i_data_wr                             (w_data_wr_osp2snp),
    .iv_tsmp_subtype                       (wv_tsmp_subtype_osp2snp),
 
    .ov_csrateoffset_previousnode          (wv_cumulativescaledrateoffset_snp2cre  ),
    .o_csrateoffset_previousnode_wr        (w_cumulativescaledrateoffset_wr_snp2cre),
      
    .ov_frequency_cor                      (wv_frequency_cor_snp2cre),
    .ov_gm_timestamps                      (wv_gm_timestamps_snp2cre         ),
    .ov_correctfield_time                  (wv_correctfield_time_snp2cre     ),
    .ov_local_cnt_rx                       (wv_local_cnt_rx_snp2cre          ),
    .ov_sync_correctfield_time             (wv_sync_correctfield_time_snp2cre),
    .ov_sync_link_delay                    (wv_sync_link_delay_snp2cre       ),
    .o_time_info_valid                     (w_time_info_valid_snp2cre        ),
    
    .ov_clk_set                            (wv_clk_set_snp2cre            ),
    .o_clk_set_wr                          (w_clk_set_wr_snp2cre          ),
    .ov_current_local_count                (wv_current_local_count_snp2cre),
    .ov_current_sync_clk                   (wv_current_sync_clk_snp2cre   ),

    .iv_frequency_cor                      (wv_frequency_cor_mpe2snp   ),
	.i_frequency_cor_wr                    (w_frequency_cor_wr_mpe2snp ),
    .ov_sync_clk                           (ov_localclk                ),
    .ov_local_count                        (wv_local_count_snp2gnp     ),
    .o_local_cnt_rst                       (o_local_cnt_rst            ),
	.o_sync_ok                             (w_snp_sync_ok                  ),
	.o_sync_ok_wr                          (o_sync_ok_wr               ),
	.ov_offset                             (wv_offset_snp2cre          ),
	.o_offset_wr                           (w_offset_wr_snp2cre        ),
	.ov_offset_abnormal_cnt                (wv_offset_abnormal_cnt_snp2other),
	.o_sync_result_wr                      (w_sync_result_wr_snp2cre        ),
 
	.ov_data                               (wv_data_snp2oss  ),
	.o_data_wr                             (w_data_wr_snp2oss)
);

cpu_report 
#(
.local_module_id(local_module_id)
)
cpu_report_inst
(
    .i_clk                                 (i_clk     ),
    .i_rst_n                               (i_rst_n   ),
 
	.iv_hcp_mid                            (iv_hcp_mid),
	.iv_os_cid                             (wv_os_cid_mpe2other),
 
	.iv_port_ptp_enabled                   (ov_port_ptp_enabled),    
    .iv_measure_sync_state_report_enabled  (wv_measure_sync_state_report_enabled_mpe2cre),
    .i_cyclestart                          (i_cyclestart),
    
    .iv_frequency_cor                      (wv_frequency_cor_snp2cre),   
    
    .iv_gm_timestamps                      (wv_gm_timestamps_snp2cre         ),
    .iv_correctfield_time                  (wv_correctfield_time_snp2cre     ),
    .iv_local_cnt_rx                       (wv_local_cnt_rx_snp2cre          ),
    .iv_sync_correctfield_time             (wv_sync_correctfield_time_snp2cre),
    .iv_sync_link_delay                    (wv_sync_link_delay_snp2cre       ),
    .i_time_info_valid                     (w_time_info_valid_snp2cre        ),
    
    .iv_clk_set                            (wv_clk_set_snp2cre            ),
    .i_clk_set_wr                          (w_clk_set_wr_snp2cre          ),
    .iv_current_local_count                (wv_current_local_count_snp2cre),
    .iv_current_sync_clk                   (wv_current_sync_clk_snp2cre   ),

	.i_sync_ok                             (o_sync_ok                       ),
	.iv_sync_abnormal_cnt                  (wv_offset_abnormal_cnt_snp2other),
	.iv_offset                             (wv_offset_snp2cre               ),
	.iv_csrateoffset_previousnode          (wv_cumulativescaledrateoffset_snp2cre),
    .i_csrateoffset_previousnode_wr        (w_cumulativescaledrateoffset_wr_snp2cre),
	.i_sync_state_wr                       (w_sync_result_wr_snp2cre        ),
 
	.iv_t1                                 (wv_t1_mrq2cre),
    .iv_t2                                 (wv_t2_mrq2cre),
    .iv_t3                                 (wv_t3_mrq2cre),	
    .iv_t4                                 (wv_t4_mrq2cre),
	.i_measure_state_wr                    (w_timestamps_valid_mrq2cre),
 
	.ov_data                               (ov_data_report  ),
	.o_data_wr                             (o_data_wr_report)
);

grandmaster_slave_select grandmaster_slave_select_inst
(
    .i_clk          (i_clk        ),
    .i_rst_n        (i_rst_n      ),
                     
	.i_gm_role      (w_gm_role_mpe2gnp    ),
                     
    .iv_data_gnp    (wv_data_gnp2oss  ),
	.i_data_wr_gnp  (w_data_wr_gnp2oss),
	                 
    .iv_data_snp    (wv_data_snp2oss  ),
	.i_data_wr_snp  (w_data_wr_snp2oss),	
	                 
	.ov_data        (wv_data_gss2oss      ),
	.o_data_wr      (w_data_wr_gss2oss    )
);

mux_5to1 opensync_transmit_control_inst
(
        .i_clk                       (i_clk            ),
        .i_rst_n                     (i_rst_n          ),
 
        .iv_data_1                   (wv_data_anp2oss  ),
	    .i_data_wr_1                 (w_data_wr_anp2oss),
        
        .iv_data_2                   (wv_data_sip2oss  ),
        .i_data_wr_2                 (w_data_wr_sip2oss),
    
        .iv_data_3                   (wv_data_mrq2oss  ),
        .i_data_wr_3                 (w_data_wr_mrq2oss),
 
        .iv_data_4                   (wv_data_mrs2oss  ),
        .i_data_wr_4                 (w_data_wr_mrs2oss),

        .iv_data_5                   (wv_data_gss2oss  ),
        .i_data_wr_5                 (w_data_wr_gss2oss),       
	 
        .ov_data                     (ov_data  ),
        .o_data_wr                   (o_data_wr),
 
        .ov_discard_pkt_cnt_fop_1    (),
        .ov_cut_pkt_cnt_fop_1        (),
        .ov_discard_pkt_cnt_fop_2    (),
        .ov_cut_pkt_cnt_fop_2        (),
        .ov_discard_pkt_cnt_fop_3    (),
        .ov_cut_pkt_cnt_fop_3        (),
        .ov_discard_pkt_cnt_fop_4    (),
        .ov_cut_pkt_cnt_fop_4        (),
        .ov_discard_pkt_cnt_fop_5    (),
        .ov_cut_pkt_cnt_fop_5        ()
							 
); 
measure_clock_timing
#(
.clk_period(clk_period)
)  
measure_clock_timing_inst
(
        .i_clk      (i_clk     ),
        .i_rst_n    (i_rst_n   ),
			 
        .ov_mea_clk (wv_mea_clk_mct2other)
);
endmodule